package com.LatitudeYao;
import java.util.*;
/**
 * Created by GTS on 2017/8/17.
    两个栈实现一个队列，显然先压入stack1
 */

public class StackToQueue {
    private Stack<Integer> stack1 = new Stack<Integer>();
    private Stack<Integer> stack2 = new Stack<Integer>();

    public  void in(int  value){//压stack1栈，
        stack1.push(value);
    }
    public int  out() throws Exception{//
        if(stack2.isEmpty()){//如果2为空则把1的压入2
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        if(stack2.isEmpty()){//弹出队列
            throw new Exception("Error");
        }

        int value = stack2.pop();
        System.out.println(value);
        return value;

    }
    public static void main(String[] args) throws Exception{
        StackToQueue  stq = new StackToQueue();
        stq.in(1);
        stq.in(2);
        stq.in(6);

        stq.in(4);
        stq.in(5);
        stq.in(7);

        stq.out();
        stq.out();
        stq.out();
        stq.out();
        stq.out();
        stq.out();




    }
}
